
<template>
    <div class="port-page">
        <!-- 顶部按钮 -->
        <el-button type="primary" class="add btn" :loading="searchLoading" @click="search" icon="search">搜索</el-button>
        <el-button type="success" class="add btn" :disabled="multipleDeleteDisabled" :loading="searchLoading" @click="chooseed" icon="search">选择</el-button>
        <el-button type="danger" class="add btn" :loading="searchLoading" @click="close" icon="search">退出</el-button>
                <!-- 模糊搜索条件 -->
        <div class="search">
            <div class="search-item">
                <span>物品分类：</span>
               <!-- <el-input placeholder="请输入物品分类id" class="code-search" v-model="vwpflid"  @keyup.enter.native="search"></el-input>-->
               <el-select v-model="vwpflid" class="input">
								<el-option :label="v.mc" :value="v.id" v-for="v in comboxlist"></el-option>
					</el-select>
            </div>
             <div class="search-item">
                <span>物品名称：</span>
                <el-input placeholder="输入物品名称" class="code-search" v-model="vkeyword"  @keyup.enter.native="search"></el-input>
            </div>

        </div>
        <!-- 数据表格展示区域 -->
        <el-table
            :data="dataList"
            border
            align="left"
            class="admin-table"
            @select="checkSelect"
             style="width: 100%"
            @select-all="checkall">
            <el-table-column type="selection" width="55"></el-table-column>
            <div slot='empty'>
                <img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
                <span style="vertical-align: middle;">暂时还没有内容哦!</span>
            </div>
            <el-table-column
                :prop="v.prop"
                :label="v.label"
                v-for="(v,index) in portTitleList"
                align="center"
                show-overflow-tooltip
                v-if="v.hide != 0"
                :formatter="v.formatter"
                :align="v.align || 'center'"
                :fixed="v.fixed"
                :class-name="v.columnStyle"
                :width="v.width"
                :min-width="v.minWidth"
                :header-align="v.headerAlign || 'center'"
                >
                <template scope="scope">
                    <div slot="reference" :style="tableCellControl(scope)">
                        {{ scope.row[scope.column.property] }}
                    </div>
                 </template>
            </el-table-column>
        </el-table>
        <!-- 分页查询区域 -->
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageindex"
            :page-sizes="pagesizes"
            :page-size="pagesize"
            :layout="layout"
            :total="total"
            class="class-page">
        </el-pagination>
        <!-- 各个组件显示区域 -->
        <!-- 动画加载 -->
        <LoadingComponent v-show="isLoading"></LoadingComponent>
     </div >
</template>
<script>
    import { mapState } from 'vuex'
    import LoadingComponent from 'components/loading'
    export default {
        components: { LoadingComponent  },
        data () {
            return {

            /*模糊搜索条件*/
		       comboxlist:[],
               vkeyword:'', // keyword

               vwpflid:'', // 物品分类id

				multipleDelNum:'', //获取批量选择的数据id
				multipleDelNummc:'', //获取批量选择的数据id

                dataList: [],  //表格数据
                vcomautovalue:'',//下拉框name 动态的
                vcomgdvalue:'',//下拉框name 固定的

				/*动画加载*/
                isLoading: true,//动画加载
                searchLoading: false,//搜索按钮触发按钮动画
                /*分页属性设置*/
                layout: 'total, sizes, prev, pager, next, jumper',//组件布局
			    pageindex: this.$store.state.pageindex,//当前分页页码
                pagesizes: this.$store.state.pagesizes,//显示个数的选择器选项
                pagesize: this.$store.state.pagesize,//每页显示条目数
                total: 0,//总条数

                /*组件区域*/
                portComponents: {
                    /* 单行删除  */
                    singleDelete: {
                        type: 'singleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'single',
                            title: '此操作将删除该记录?, 是否继续?'
                        }
                    },
                    /* 批量删除 */
                    multipleDelete: {
                        type: 'multipleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'multiple',
                            title: '此操作将删除您选中的记录?, 是否继续?'
                        }
                    }
                },
                /*
                    prop :  接口参数名
                    label : 接口中文名
                    hide : 是否隐藏这一列
                    align : 这一列对齐顺序 ： left,right,center
                    headerAlign : 这一列表头对齐方式 ： left,right,center
                */
                portTitleList: [

                    {
                        prop:'id',
                        label:'物品id',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'xxid',
                        label:'学校id',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'wpflid',
                        label:'物品分类id-T_wpfl.id',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'wpflmc',
                        label:'分类名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'150',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'mc',
                        label:'物品名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'ms',
                        label:'描述',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'100',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'jg',
                        label:'价格',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'80',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'dw',
                        label:'单位',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'65',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                     {
                        prop:'kcsl',
                        label:'库存数量',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'sfsj',
                        label:'是否上架',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'100',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'ispj',
                        label:'配件说明',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'100',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'wpurl',
                        label:'物品图片',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'xgr',
                        label:'修改人',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'100',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'crttime',
                        label:'修改时间',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'180',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    }

                ]
            }
        },
        created () {
            //加载页面时调用
            this.search();//分页获取默认数据
            this.isLoading = true;//动画开始
             this.getcomboxlist();//加载下拉
        },
        mounted () {
            //加载完成之后event
            this.isLoading = false;//动画结束
        },
        methods: {
        	chooseed(){
        		this.$emit('wpchoose', { wpid: this.multipleDelNum, wpmc:this.multipleDelNummc })
        	},
        	close(){
        		this.$emit('close',"" )
        	},
          search () {
		    //查询搜索触发事件
            var logininfo = JSON.parse(localStorage.logininfo) ;
              this.searchLoading = true;
              this.axios.get(this.$store.state.api + 'wpfx/list',{
                  params:{

              keyword: this.vkeyword, // keyword
              wpflid: this.vwpflid, // 物品分类id
                      yhid:logininfo.id,
                      xxid:logininfo.xxid,
                      pageindex: this.pageindex,
                      pagesize: this.pagesize
                  }
              }).then( res => {
                  console.log(res)
                  let data = res.data.data;
                  let list = data.list;
                  this.total = data.totalPage;
                  this.dataList = list;
                  this.searchLoading = false;
              }).catch( res => {
                  console.log(res)
                  this.searchLoading = false;
              })
          },
         getcomboxlist(){
				var logininfo = JSON.parse(localStorage.logininfo) ;
					this.searchLoading = true;
					this.axios.get(this.$store.state.api + 'wpfl/list',{
							  params:{

              keyword: this.vkeyword, // keyword
              wpflid: this.vwpflid, // 物品分类id
                      yhid:logininfo.id,
                      xxid:logininfo.xxid,
                      pageindex: this.pageindex,
                      pagesize: this.pagesize
                  }
					}).then( res => {
							console.log(res)
							let data = res.data.data;
							let list = data.list;
							this.comboxlist=list;
							console.log(this.comboxlist)
					}).catch( res => {
							console.log(res)
							this.searchLoading = false;
					})
			},
          tableCellControl (scope) {
            //表格单元格控制CSS样式
                /*if (scope.row.id == 112 && scope.column.property == "iname") {
                    return {
                        color:"red",
                    }
                }else{
                    return {
                        color:"green",
                    }
                }*/
           },
           handleSizeChange (val) {//每页显示条数触发事件
                this.pagesize = val;
                this.pageindex = 1;
                this.search();
            },
            handleCurrentChange (val) {//分页触发事件
                this.search();
            },
            checkSelect (selection, row) {//点击单选select触发事件
                let strID = [];
                let strIDmc =[];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                    strIDmc.push(v.mc)
                })
                this.multipleDelNum = strID.join(",");
                this.multipleDelNummc = strIDmc.join(",");

            },
            checkall (selection) {//点击全选select触发事件
                let strID = [];
                let strIDmc =[];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                    strIDmc.push(v.mc)
                })
                this.multipleDelNum = strID.join(",");
                this.multipleDelNummc = strIDmc.join(",");
            },
            /* 组件的弹框  */
            componentsShow (type,data) { //显示组件
                console.log(type,data)
                for ( let i in this.portComponents ) {
                    if (type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = true;
                        this.portComponents[i].params = data;
                        if (this.portComponents[i].data.type == 'single') {
                            this.portComponents[i].data.index = data.row.id
                        }else if(this.portComponents[i].data.type == 'multiple'){
                            this.portComponents[i].data.index = this.multipleDelNum;
                        }else{
                            return;
                        }
                        return;
                    }
                }
            },
            componentsHide (setting) { //关闭组件
                console.log(setting)
                for ( let i in this.portComponents ) {
                    if (setting.type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = false;
                        if (!setting.cancel) {
                           this.search();
                        }
                        return;
                    }
                }
            }
        },
        computed: {
            ...mapState([
                'api'//域名
            ]),
            multipleDeleteDisabled () {
                console.log(this.multipleDelNum)
                if (this.multipleDelNum) {
                    return false;
                }else{
                    return true
                }
            }
        }
    }
</script>

<style lang="less" scoped>
    .port-page {
        font-size:12px;
        .btn {
            height: 30px;
            padding:0 10px;
            margin-top:10px ;
            margin-left: 10px;
        }
        .code-search {
            width: 200px;
            height: 30px;
            margin:10px 0 10px 0;
        }
        .change-time{
            width: 480px;
            display: inline-block;
        }
        .class-page {
            text-align: left;
            margin-top:10px;
        }
        .search-item {
            display: inline-block;
            margin-right:10px;
            margin-left: 10px;
        }
        .wrap .wpfl{
    background: #fff;
    position: absolute;
    top: 5px;
    right: -15%;
    }
    }
</style>
